import 'package:flutter/material.dart';
import 'package:flutter_advanced_drawer/flutter_advanced_drawer.dart';
import 'package:get/get.dart';
import 'package:sj001/pages/chatPage/chatPage.dart';
import 'package:sj001/pages/lastPage/lastPage.dart';
import 'package:sj001/pages/searchPage/searchPage.dart';
import 'package:sj001/pages/suggestPage/suggestPage.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage(
      {required this.advancedDrawerController, super.key});

  AdvancedDrawerController advancedDrawerController;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  late TabController tabCtr;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabCtr = TabController(length: 3, vsync: this);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    tabCtr.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.sizeOf(context);
    EdgeInsets padding = MediaQuery.paddingOf(context);

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: TabBar(
          controller: tabCtr,
          labelColor: Colors.black,
          indicatorSize: TabBarIndicatorSize.label,
          tabs: const [
            Tab(text: 'GLM-4'),
            Tab(text: '最近'),
            Tab(text: '推荐'),
          ],
        ),
        leading: InkWell(
          onTap: () => widget.advancedDrawerController.toggleDrawer(),
          child: Icon(
            Icons.menu,
            size: 30,
          ),
        ),
        actions: [
          InkWell(
            onTap: () => Get.to(() => const SearchPage()),
            child: const Padding(
              padding: EdgeInsets.only(right: 20),
              child: Icon(
                Icons.search,
                size: 30,
              ),
            ),
          ),
        ],
      ),
      body: getContainer(),
    );
  }

  Widget getContainer() {
    return Container(
      alignment: Alignment.center,
      child: TabBarView(
        controller: tabCtr,
        children: [
          ChatPage(conversation_id: ''),
          const LastPage(),
          const SuggestPage(),
        ],
      ),
    );
  }
}
